package code.remote.request {

import code.Model;
import code.vo.User;

import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
	

public class FetchUsersRequest extends AbstractRequest {
	
	public function FetchUsersRequest() {
		super("fetch_users");
	}
	
	protected final override function onResult(event: ResultEvent): void {
		const result: ArrayCollection = new ArrayCollection();
		
		const usersObject: Object = event.result.Users;
		if(usersObject == null) {
			// no users at all
		} else if(usersObject.User is ArrayCollection) {
			for each(var userXmlNode: Object in usersObject.User) {
				result.addItem(User.newByXml(userXmlNode));
			}
		} else {
			result.addItem(User.newByXml(usersObject.User));
		}
		
		Model.instance.setUsers(result);
	}
}
}